/**
 * Show plural label if time is plural number
 * @param {number} time
 * @param {string} label
 * @return {string}
 */
function pluralize(time, label) {
	if (time === 1) {
		return time + label;
	}
	return time + label + 's';
}

/**
 * @param {number} time
 */
export function timeAgo(time) {
	const between = Date.now() / 1000 - Number(time);
	if (between < 3600) {
		return pluralize(~~(between / 60), ' minute');
	} else if (between < 86400) {
		return pluralize(~~(between / 3600), ' hour');
	} else {
		return pluralize(~~(between / 86400), ' day');
	}
}
